#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 110, M = N * (N - 1) / 2;
int p[N];
int n, m;
int a, b, w;
int find(int x)
{
	if (x != p[x]) {
		p[x] = find(p[x]);
	}
	return p[x];
}
struct S
{
	int a, b, w;
}s[M];
int cmp(S a, S b)
{
	return a.w < b.w;
}
int kruskal()
{
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		p[i] = i;
	}
	sort(s, s + m, cmp);
	for (int i = 0; i < m; i++) {
		int a = find(s[i].a);
		int b = find(s[i].b);
		if (a != b) {
			p[a] = b;
			ans += s[i].w;
		}
	}
	return ans;
}
int main()
{
	while (scanf("%d",&n)) {
		if (!n) {
			break;
		}
		memset(s, 0, sizeof(s));
		memset(p, 0, sizeof(p));
		m = n * (n - 1) / 2;
		for (int i = 0; i < m; i++) {
			scanf("%d%d%d", &a, &b, &w);
			s[i] = { a,b,w };
		}
		cout << kruskal() << endl;
	}
	return 0;
}